﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

namespace ClinicalMassageSystem
{
    public partial class UpdateConnectionString : Form
    {
        public UpdateConnectionString()
        {
            InitializeComponent();
        }

        private void btnUpdateDBConn_Click(object sender, EventArgs e)
        {
            string connName = txtConnName.Text;
            string serverName = txtServer.Text;
            string fileName = txtDBFile.Text;

            if (serverName.Equals("") || fileName.Equals("") || connName.Equals(""))
                MessageBox.Show("You must fill in all parameters");
            else
            {
                ConnectionStringSettings css = new ConnectionStringSettings();
                css.Name = connName;
                css.ProviderName = "System.Data.SqlClient";
                css.ConnectionString = "Data Source=" + serverName + ";AttachDbFilename=|DataDirectory|" + fileName + ";Integrated Security=True;User Instance=False";

                ConnectionStringSettingsCollection settings =
                ConfigurationManager.ConnectionStrings;
                settings.Add(css);
            }
        }
    }
}
